package com.ambulance.project.biz.controller.common;

import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.project.biz.controller.common.dto.DeviceUrl;
import com.ambulance.project.biz.util.xml.ParseXmldom4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.Map;

/**
 * @Author RXL
 * @Date 2020/6/29 22:16
 * @Version 1.0
 */
@Api(tags = "多端共用-心电图页面")
@RestController
public class BrController
{

    @Value(("${br.indexUrl}"))
    private String indexUrl;
    @Value(("${br.detailUrl}"))
    private String detailUrl;
    @Value(("${br.respiratorUrl}"))
    private String respiratorUrl;

    @Value(("${mairy.xmlPath}"))
    private String xmlPath;

    @ApiOperation(value = "设备（心电图、呼吸机）iframe嵌入页面地址",
            notes = "设备（心电图、呼吸机）iframe嵌入页面地址," +
                    "获取的地址嵌入各端需要根据各自场景携带必要的参数（注意参数大小写）：" +
                    "dispatcherId（调度id）、" +
                    "actionFlag（1回放、0实时）、" +
                    "color（canvas图渲染颜色，默认000），" +
                    "实例：http://60.205.202.107:8084/new/detail?dispatcherId=10032&actionFlag=1&color=00184c"
    )

    @ApiResponses({
            @ApiResponse(code = 200, response = DeviceUrl.class, message = "响应")
    })
    @RequestMapping(value = "/common/deviceurl", method = RequestMethod.POST)
    public AjaxResult br()
    {
        DeviceUrl deviceUrl = new DeviceUrl();
        deviceUrl.setIndexUrl(indexUrl);
        deviceUrl.setDetailUrl(detailUrl);
        deviceUrl.setRespiratorUrl(respiratorUrl);
        return AjaxResult.success(deviceUrl);
    }

    @RequestMapping(value = "/comm/xml/dispatch/{id}", method = RequestMethod.GET)
    public AjaxResult xml(@PathVariable("id") Long id)
    {
        String dir = xmlPath + id + "/";
        File file = new File(dir);
        File xml = null;
        if (file.isDirectory())
        {
            File[] files = file.listFiles();
            xml = files[0];
        }
        Map<String, Object> stringObjectMap = ParseXmldom4j.parseMaiRuiXml(xml.getAbsolutePath());
        return AjaxResult.success(stringObjectMap);
    }

}
